package com.fht.service.inventory.impl;

import com.fht.entity.InventoryParticulars;
import com.fht.mapper.inventory.InventoryParticularsMapper;
import com.fht.service.inventory.InventoryParticularsService;
import com.fht.util.DateTimeUtil;
import com.fht.vo.LayUITableVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Slf4j
@Service
public class InventoryParticularsServiceImpl implements InventoryParticularsService {

    @Resource
    public InventoryParticularsMapper inventoryParticularsMapper;


    @Override
    public void save(Integer id,Integer oldRepertory, Integer change) {

        InventoryParticulars inventoryParticulars = new InventoryParticulars();

        inventoryParticulars.setRecordId(id);
        inventoryParticulars.setDate(DateTimeUtil.nowDate());
        //TODO 登录用户
        inventoryParticulars.setOperator("小红");
        inventoryParticulars.setOperatorWay("库存编辑");
        inventoryParticulars.setOldRepertory(oldRepertory);
        inventoryParticulars.setChangeRepertory(change);

        inventoryParticularsMapper.insertSelective(inventoryParticulars);
    }

    @Override
    public void save(Integer id, Integer oldRepertory, Integer change, String orderId) {
        InventoryParticulars inventoryParticulars = new InventoryParticulars();

        inventoryParticulars.setRecordId(id);
        inventoryParticulars.setDate(DateTimeUtil.nowDate());
        inventoryParticulars.setOperator(orderId);
        inventoryParticulars.setOperatorWay("库存编辑");
        inventoryParticulars.setOldRepertory(oldRepertory);
        inventoryParticulars.setChangeRepertory(change);

        inventoryParticularsMapper.insertSelective(inventoryParticulars);
    }

    @Override
    public LayUITableVO<List<InventoryParticulars>> findPage(Map<String, Object> map) {
        PageHelper.startPage((int) map.get("page"),(int) map.get("limit"));



        List<InventoryParticulars> list = inventoryParticularsMapper.findPage(map);

        PageInfo<InventoryParticulars> pageInfo = new PageInfo<>(list);

        LayUITableVO<List<InventoryParticulars>> vo = new LayUITableVO<>();
        vo.setCount(pageInfo.getTotal());
        vo.setData(pageInfo.getList());

        return vo;
    }
}
